/**
 * SUNING APPLIANCE CHAINS.
 * Copyright (c) 2010-2010 All Rights Reserved.
 */
package com.example.common.result;

import java.io.Serializable;

/**
 * 结果类
 *
 * @author 陈书元 2010-7-17
 */
public class Result implements Serializable {

    private static final long serialVersionUID = 4425372968541587317L;

    public static final int SUCCESS = 0;

    public static final int FAIL = 1;

    public static final int NO_PERMISSION = 2;

    private boolean success = true;

    private int code = SUCCESS;

    private String msg = "success";

    /**
     * 失败
     */
    public void fail(String msg) {
        this.code = FAIL;
        this.msg = msg;
        this.success = false;
    }

    /**
     * 失败
     *
     * @param code 错误码
     * @param msg  结果信息
     */
    public void fail(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.success = false;
    }

    /**
     * 无权限
     */
    public void failPermission() {
        this.code = NO_PERMISSION;
        this.msg = "无权限";
        this.success = false;
    }

    /**
     * 获取错误码
     *
     * @return 错误码
     */
    public int getCode() {
        return code;
    }

    /**
     * 设置错误码
     *
     * @param code 错误码
     */
    public void setCode(int code) {
        this.code = code;
    }

    /**
     * 获取结果信息
     *
     * @return 结果信息
     */
    public String getMsg() {
        return msg;
    }

    /**
     * 设置结果信息
     *
     * @param msg 结果信息
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
